import React, { Component } from 'react';
import Child from "./child.jsx";

export default class Parent extends Component {
    state={
        hasError:""
    };
    static getDerivedStateFromError(error){
        console.log("======",error);
        return {
            hasError:error
        };
    };
    componentDidCatch(error,info){
        console.log("渲染组件出错",error,info);
    };
    render() {
        return (
            <div>
                <h2>我是Parent组件</h2>
                {this.state.hasError ? <h2>网络不稳定，稍后再试！</h2> : <Child></Child> }
            </div>
        );
    };
};
